﻿/*
 * Created by SharpDevelop.
 * User: notmmao
 * Date: 2008-3-29
 * Time: 10:45
 * 
 */

using System;
using System.Drawing;

namespace Deebug.Games.ShortBoom
{
	/// <summary>
	/// 双缓冲辅助类
	/// </summary>
	public class DBGraphics
	{
		private	Graphics graphics;
		//后台缓冲图片
		private Bitmap	memoryBitmap;
		//原始缓冲图片
		private Bitmap	memoryBitmap2;
		
		/// <summary>
		/// 获取后台缓冲图片的Graphics
		/// </summary>
		public Graphics BackGroundGraphics {
			get {
				return graphics;
			}
		}

		/// <summary>
		/// 默认构造函数
		/// </summary>
		public DBGraphics(Bitmap bitmap){
			if (memoryBitmap != null)
			{
				memoryBitmap.Dispose();
				memoryBitmap = null;
			}

			if (graphics != null)
			{
				graphics.Dispose();
				graphics = null;
			}
			
			memoryBitmap	= new Bitmap(bitmap.Width,bitmap.Height);
			graphics		= Graphics.FromImage(memoryBitmap);
			memoryBitmap2 = bitmap;
		}
		
		/// <summary>
		///绘制内存缓冲图片
		/// </summary>
		/// <param name="g"></param>
		public void Render(Graphics g)
		{
			g.DrawImage(memoryBitmap,0,0);
			this.graphics.DrawImage(memoryBitmap2,0,0,memoryBitmap2.Width,memoryBitmap2.Height);
		}
	}
}
